package com.stations.domain.transmitterEntity;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author Geordie
 * @version 0.0.1
 * @description TransmitterTransmitterResult
 * @since 2023/3/31 10:50
 */
@Data
@Accessors(chain = true)
public class TransmitterResult<T> implements Serializable {
    private static final long serialVersionUID = -2243004256529006189L;



    private Integer code;

    private String msg;

    private T data;

    public TransmitterResult() {
    }

    protected static <T> TransmitterResult<T> build(T data) {
        TransmitterResult<T> transmitterResult = new TransmitterResult<T>();
        if (data != null) {
            transmitterResult.setData(data);
        }
        return transmitterResult;
    }

    public static <T> TransmitterResult<T> build(T body, TransmitterResultEnum resultCodeEnum) {
        TransmitterResult<T> transmitterResult = build(body);
        transmitterResult.setCode(resultCodeEnum.getCode());
        transmitterResult.setMsg(resultCodeEnum.getMsg());
        return transmitterResult;
    }

    public static <T> TransmitterResult<T> build(TransmitterResultEnum resultCodeEnum) {
        TransmitterResult<T> transmitterResult = new TransmitterResult<T>();
        transmitterResult.setCode(resultCodeEnum.getCode())
                .setMsg(resultCodeEnum.getMsg());
        return transmitterResult;
    }

    /**
     * 不支持的请求编码字符集
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> codingError() {
        return build(TransmitterResultEnum.codingError);
    }

    /**
     * 解析请求JSON数据异常
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> jsonError() {
        return build(TransmitterResultEnum.jsonError);
    }

    /**
     * 签名不正确
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> signatureError() {
        return build(TransmitterResultEnum.signatureError);
    }

    /**
     * 系统内部异常
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> insideError() {
        return build(TransmitterResultEnum.insideError);
    }

    /**
     * 参数格式不正确
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> formatError() {
        return build(TransmitterResultEnum.formatError);
    }

    /**
     * 参数范围不正确
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> rangeError() {
        return build(TransmitterResultEnum.rangeError);
    }

    /**
     * 必填参数为空
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> isNullError() {
        return build(TransmitterResultEnum.isNullError);
    }

    /**
     * 参数错误
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> parameterError() {
        return build(TransmitterResultEnum.parameterError);
    }

    /**
     * 其他错误
     *
     * @param data 错误信息
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> error(T data) {
        TransmitterResult<T> TransmitterResult = build(data);
        return build(data, TransmitterResultEnum.error);
    }

    /**
     * 操作成功
     *
     * @param data 返回参数
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> success(T data) {
        TransmitterResult<T> TransmitterResult = build(data);
        return build(data, TransmitterResultEnum.success);
    }
    /**
     * 操作成功
     *
     * @param <T>
     * @return
     */
    public static <T> TransmitterResult<T> success() {
        return  build(TransmitterResultEnum.success);
    }
}
